package com.edu.hello;

import java.util.Random;
import java.util.Scanner;

public class arrayDemo02 {
    public static void main(String[] args) {
        //数组猜数字游戏
        Random r = new Random();
        int[] a=new int[5];
        for (int i = 0; i < 5; i++) {
            a[i]=r.nextInt(20)+1;
        }
        Scanner scanner = new Scanner(System.in);
        OUT:
        while(true){
            int nextInt = scanner.nextInt();
            for (int i = 0; i < a.length; i++) {
                if(nextInt==a[i]){
                    System.out.println("索引是"+i);
                    break OUT;
                }
            }
        }
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]+"\t");
        }
        System.out.println("------------------------");
        int[] array=new int[5];
        for (int i = 0; i < 5; i++) {
            System.out.println("输入第"+(i+1)+"名员工的成绩");
            int i1 = scanner.nextInt();
            array[i]=i1; //放入数组
        }
        //随机生成索引，然后随机对换位置
        for (int i = 0; i < array.length; i++) {
            int c = r.nextInt(array.length - 1);
            int temp=array[c];
            array[c]=array[i];
            array[i]=temp;
        }
        //随机数组输出
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+"\t");
        }
        //冒泡排序将随机数组重新排列
        for (int i = 0; i <array.length-1 ; i++) {
            for (int j = 0; j < array.length - i-1; j++) {
                if(array[j]>array[j+1]){
                    int temp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=temp;
                }
            }
        }
        System.out.println();
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+"\t");
        }
    }
}
